function(add_tsd_object)
	set(OBJECT_NAME tsd)
	foreach (ARG IN LISTS ARGV)
		set(OBJECT_NAME ${OBJECT_NAME}__${ARG})
	endforeach ()
	aux_source_directory(. ${OBJECT_NAME}_SOURCE)
	add_library(${OBJECT_NAME}_OBJECT OBJECT
			${${OBJECT_NAME}_SOURCE})
	if (BUILD_TEST_ONLY)
		target_include_directories(${OBJECT_NAME}_OBJECT PUBLIC
				${SELF_DEBUG_INCLUDE_DIR}
				${LIB_DWARF_INCLUDE_DIR})
	else ()
		target_include_directories(${OBJECT_NAME}_OBJECT PUBLIC
				${CMAKE_SOURCE_DIR}/src
				${LIB_DWARF_INCLUDE_DIR})
	endif ()
endfunction()

add_tsd_object()

add_executable(tsd
		$<TARGET_OBJECTS:tsd_OBJECT>)
set_target_properties(tsd PROPERTIES OUTPUT_NAME TestSelfDebug)
if (BUILD_TEST_ONLY)
	target_link_libraries(tsd PUBLIC
			${SELF_DEBUG_LIBRARIES}
			${LIB_DWARF_LIBRARIES}
			${LIB_UNWIND_LIBRARIES})
else ()
	target_link_libraries(tsd PUBLIC
			sd_SHARED
			${LIB_DWARF_LIBRARIES}
			${LIB_UNWIND_LIBRARIES})
endif ()
install(TARGETS tsd DESTINATION test/bin)
